<template>
  <div v-if="show" class="loading-overlay">
    <div class="loading-spinner">
      <div class="spinner-wrapper">
        <div class="spinner"></div>
        <div class="spinner-inner"></div>
      </div>
      <div class="loading-text">加载中<span class="dots">...</span></div>
    </div>
  </div>
</template>

<script setup>
const loading = useState('global-loading', () => false)
const show = computed(() => loading.value)
</script>

<style scoped>
.loading-overlay {
  position: absolute;
  /* 改为 absolute 定位 */
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(4px);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 9999;
}

.loading-spinner {
  text-align: center;
  animation: fadeIn 0.3s ease-in;
}

.spinner-wrapper {
  position: relative;
  width: 60px;
  height: 60px;
  margin: 0 auto;
}

.spinner {
  width: 100%;
  height: 100%;
  border: 3px solid #e0e0e0;
  border-top: 3px solid #3498db;
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

.spinner-inner {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 70%;
  height: 70%;
  border: 3px solid #e0e0e0;
  border-top: 3px solid #2ecc71;
  border-radius: 50%;
  transform: translate(-50%, -50%);
  animation: spin-reverse 0.8s linear infinite;
}

.loading-text {
  margin-top: 15px;
  color: #444;
  font-size: 16px;
  font-weight: 500;
  letter-spacing: 1px;
}

.dots {
  animation: dots 1.5s infinite;
  display: inline-block;
}

@keyframes spin {
  0% {
    transform: rotate(0deg);
  }

  100% {
    transform: rotate(360deg);
  }
}

@keyframes spin-reverse {
  0% {
    transform: translate(-50%, -50%) rotate(360deg);
  }

  100% {
    transform: translate(-50%, -50%) rotate(0deg);
  }
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }

  to {
    opacity: 1;
  }
}

@keyframes dots {

  0%,
  20% {
    content: '.';
  }

  40% {
    content: '..';
  }

  60%,
  100% {
    content: '...';
  }
}
</style>